home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / frntsdk1.cpt / Frontier SDK 1.0 ƒ / Applet Toolkit / quickdraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-03  |  3.6 KB  |  251 lines

  1.  
  2. /*⌐ Copyright 1988-1991 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletinternal.h"
  6. #include "font.h"
  7. #include "quickdraw.h"
  8.  
  9.  
  10. #define ctpens 5 /*we can remember pens up to 5 levels deep*/
  11.  
  12. short toppens = 0;
  13.  
  14. PenState penstack [ctpens];
  15.  
  16.  
  17. #define ctports 5 /*we can remember ports up to 5 levels deep*/
  18.  
  19. short topport = 0;
  20.  
  21. GrafPtr portstack [ctports];
  22.  
  23.  
  24. #define ctclip 5 /*we can remember clips up to 5 levels deep*/
  25.  
  26. short topclip = 0;
  27.  
  28. Rect clipstack [ctclip];
  29.  
  30.  
  31. #define ctstyle 5 /*we can remember font/size/styles up to 5 levels deep*/
  32.  
  33. short topstyle = 0;
  34.  
  35. struct {short fnum, fsize, fstyle;} stylestack [ctstyle];
  36.  
  37.  
  38. boolean pushpen () {
  39.     
  40.     if (toppens >= ctpens)
  41.         return (false);
  42.         
  43.     GetPenState (&penstack [toppens++]);
  44.     
  45.     return (true);
  46.     } /*pushpen*/
  47.     
  48.  
  49. boolean poppen () {
  50.     
  51.     if (toppens <= 0)
  52.         return (false);
  53.         
  54.     SetPenState (&penstack [--toppens]);
  55.     
  56.     return (true);
  57.     } /*poppen*/
  58.     
  59.  
  60. boolean pushmacport (p) GrafPtr p; {
  61.     
  62.     if (topport >= ctports) {
  63.         
  64.         DebugStr ((ConstStr255Param)"\ppushmacport: no room on stack");
  65.         
  66.         return (false);
  67.         }
  68.  
  69.     portstack [topport++] = quickdrawglobal (thePort);
  70.     
  71.     if (p != nil)
  72.         SetPort (p);
  73.         
  74.     return (true);
  75.     } /*pushmacport*/
  76.         
  77.  
  78. boolean popmacport () {
  79.     
  80.     if (topport <= 0) {
  81.         
  82.         DebugStr ((ConstStr255Param)"\ppopmacport: nothing on stack");
  83.         
  84.         return (false);
  85.         }
  86.     
  87.     SetPort (portstack [--topport]);
  88.     
  89.     return (true);
  90.     } /*popmacport*/
  91.  
  92.  
  93. boolean pushclip (r) Rect r; {
  94.     
  95.     register RgnHandle rgn;
  96.     
  97.     if (topclip >= ctclip)
  98.         return (false);
  99.     
  100.     GetClip (rgn = NewRgn ());
  101.     
  102.     clipstack [topclip++] = (**rgn).rgnBBox;
  103.     
  104.     DisposeRgn (rgn);
  105.     
  106.     ClipRect (&r);
  107.     
  108.     return (true);
  109.     } /*pushclip*/
  110.         
  111.  
  112. boolean popclip () {
  113.     
  114.     if (topclip <= 0)
  115.         return (false);
  116.     
  117.     ClipRect (&clipstack [--topclip]);
  118.     
  119.     return (true);
  120.     } /*popclip*/
  121.  
  122.  
  123. boolean pushstyle (fnum, fsize, fstyle) short fnum, fsize, fstyle; {
  124.     
  125.     if (topstyle >= ctstyle)
  126.         return (false);
  127.         
  128.     getfontsizestyle (
  129.         &stylestack [topstyle].fnum, 
  130.         
  131.         &stylestack [topstyle].fsize, 
  132.         
  133.         &stylestack [topstyle].fstyle);
  134.     
  135.     topstyle++;
  136.     
  137.     setglobalfontsizestyle (fnum, fsize, fstyle);
  138.     
  139.     return (true);
  140.     } /*pushstyle*/
  141.         
  142.  
  143. boolean popstyle (void) {
  144.     
  145.     if (topstyle <= 0)
  146.         return (false);
  147.     
  148.     topstyle--;
  149.     
  150.     setfontsizestyle (
  151.         stylestack [topstyle].fnum, 
  152.         
  153.         stylestack [topstyle].fsize, 
  154.         
  155.         stylestack [topstyle].fstyle);
  156.         
  157.     return (true);
  158.     } /*popstyle*/
  159.  
  160.  
  161. short getmenubarheight (void) {
  162.     
  163.     return (GetMBarHeight ()); /*call Script Manager routine*/
  164.     } /*getmenubarheight*/
  165.  
  166.  
  167. void localtoglobalrect (Rect *rchanged) {
  168.  
  169.     Point p1, p2;
  170.     Rect r;
  171.     
  172.     r = *rchanged;
  173.     
  174.     p1.h = r.left;
  175.     
  176.     p1.v = r.top;
  177.     
  178.     LocalToGlobal (&p1);
  179.     
  180.     p2.h = r.right;
  181.     
  182.     p2.v = r.bottom;
  183.     
  184.     LocalToGlobal (&p2);
  185.     
  186.     Pt2Rect (p1, p2, &r);
  187.     
  188.     *rchanged = r;
  189.     } /*localtoglobalrect*/
  190.     
  191.     
  192. void eraserect (r) Rect r; {
  193.     
  194.     EraseRect (&r);
  195.     } /*eraserect*/
  196.     
  197.     
  198. void invalrect (r) Rect r; {
  199.     
  200.     InvalRect (&r);
  201.     } /*invalrect*/
  202.     
  203.  
  204. static short absint (short x) {
  205.     
  206.     if (x < 0)
  207.         x = -x;
  208.         
  209.     return (x);
  210.     } /*absint*/
  211.     
  212.     
  213. short pointdist (Point pt1, Point pt2) {
  214.     
  215.     return (absint (pt1.h - pt2.h) + absint (pt1.v - pt2.v));
  216.     } /*pointdist*/
  217.  
  218.  
  219. void centerrect (Rect *rcentered, Rect rcontains) {
  220.     
  221.     /*
  222.     center the first rectangle within the second rectangle.
  223.     */
  224.     
  225.     register short height, width;
  226.     Rect r;
  227.     
  228.     r = *rcentered;
  229.     
  230.     width = r.right - r.left;
  231.     
  232.     r.left = rcontains.left + ((rcontains.right - rcontains.left - width) / 2);
  233.     
  234.     r.right = r.left + width;
  235.     
  236.     height = r.bottom - r.top;
  237.     
  238.     r.top = rcontains.top + ((rcontains.bottom - rcontains.top - height) / 2);
  239.     
  240.     r.bottom = r.top + height;
  241.     
  242.     *rcentered = r;
  243.     } /*centerrect*/
  244.  
  245.  
  246.     
  247.     
  248.     
  249.     
  250.     
  251.